package com.example.videoconverter;

import java.io.File;
import java.util.Map;

/**
 * 简单转换方法的测试类
 * 用于测试不依赖JavaCV的simpleConvertAviToMp4方法
 */
public class SimpleConverterTest {
    
    public static void main(String[] args) {
        System.out.println("=== 简化AVI转MP4转换测试 ===");
        System.out.println("测试不依赖JavaCV的转换方法\n");
        
        VideoConverter converter = new VideoConverter();
        
        // 测试文件路径
        String inputPath = "target/classes/sample_1280x720.avi";
        String outputPath = "target/simple_test_output.mp4";
        
        try {
            // 检查输入文件是否存在
            File inputFile = new File(inputPath);
            if (!inputFile.exists()) {
                System.out.println("错误: 输入文件不存在: " + inputPath);
                System.out.println("请确保项目中有测试视频文件");
                return;
            }
            
            System.out.println("输入文件: " + inputPath);
            System.out.println("输出文件: " + outputPath);
            System.out.println("输入文件大小: " + String.format("%.2f MB", inputFile.length() / (1024.0 * 1024.0)));
            
            // 获取输入视频信息
            System.out.println("\n--- 输入视频信息 ---");
            Map<String, Object> inputInfo = converter.getVideoInfo(inputPath);
            System.out.println("宽度: " + inputInfo.get("width"));
            System.out.println("高度: " + inputInfo.get("height"));
            System.out.println("时长: " + inputInfo.get("duration") + " 秒");
            System.out.println("格式: " + inputInfo.get("format"));
            
            // 执行简化转换
            System.out.println("\n--- 开始简化转换 ---");
            long startTime = System.currentTimeMillis();
            
            converter.simpleConvertAviToMp4(inputPath, outputPath);
            
            long endTime = System.currentTimeMillis();
            double duration = (endTime - startTime) / 1000.0;
            
            // 验证输出文件
            File outputFile = new File(outputPath);
            if (outputFile.exists()) {
                System.out.println("\n--- 转换成功 ---");
                System.out.printf("转换耗时: %.2f 秒%n", duration);
                System.out.printf("输出文件大小: %.2f MB%n", outputFile.length() / (1024.0 * 1024.0));
                System.out.printf("压缩比: %.2f%%%n", (double) outputFile.length() / inputFile.length() * 100);
                
                // 获取输出视频信息
                System.out.println("\n--- 输出视频信息 ---");
                Map<String, Object> outputInfo = converter.getVideoInfo(outputPath);
                System.out.println("宽度: " + outputInfo.get("width"));
                System.out.println("高度: " + outputInfo.get("height"));
                System.out.println("时长: " + outputInfo.get("duration") + " 秒");
                System.out.println("格式: " + outputInfo.get("format"));
                
                System.out.println("\n✅ 简化转换测试成功！");
                System.out.println("输出文件: " + outputFile.getAbsolutePath());
                
            } else {
                System.out.println("\n❌ 转换失败: 输出文件未生成");
            }
            
        } catch (Exception e) {
            System.out.println("\n❌ 转换过程中发生错误:");
            System.out.println("错误信息: " + e.getMessage());
            e.printStackTrace();
        }
    }
}